< previous page page_365 next page >

Page 365
Using Property Get with Objects
If you understand the code in the preceding section, then you know that the Property Get procedure is used to return values from the object and the Property Let procedure is used to accept values from the calling program. However, the Property Let procedure does not work with objects. For this reason, if the parameter is an object, you need to substitute the Property Set procedure, as in the following code:
Private objSupervisor As clsEmployee

Public Property Get Supervisor() As clsEmployee
    Set Supervisor = objSupervisor
End Property

Public Property Set Supervisor(objBoss As clsEmployee)
    Set objSupervisor = objBoss
End Property
Notice the Set statement, which is used to set the value of an object. Set also has to be used by the calling code that accesses the property procedures:
Dim objEmployee As New clsEmployee
Dim objBoss As New clsEmployee

objEmployee.FirstName = "George"
objEmployee.LastName = "Jetson"
objBoss.FirstName = "Mr."
objBoss.LastName = "Spacely"

Set objEmployee.Supervisor = objBoss

Msgbox "George's Boss is " & objEmployee.Supervisor.LastName
Adding Methods to the Class
As you may have noticed, objects can have methods, such as the Print method of the PictureBox control. You can create methods in your own class by adding public procedures to the class module. Public procedures work just like regular subroutines and functions, but the Public keyword indicates that they will be visible to users of your object. For example, the following CalcRaise procedure could be added to the employee object:
Public Function CalcRaise() As Currency
    Dim sgPercentRaise As Single

    Select Case DateDiff("yyyy", Me.DateHired, Now)
        Case Is > 1
            sgPercentRaise = 0.06
        Case Is <= 1
            sgPercentRaise = 0.02
    End Select

    CalcRaise = Me.Salary * sgPercentRaise + Me.Salary

End Function

 
< previous page page_365 next page >